<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />

    <title><spring:message code="pattern.yinhua"></spring:message></title>
 <link href="${pageContext.request.contextPath }/phone/css/cssfolder/cssstyle/stylefloder.css" rel="stylesheet" type="text/css" />   
 <link href="${pageContext.request.contextPath }/phone/css/xiadan.css" rel="stylesheet" />
    <style>
    .spinner{float:left;}
    </style>
</head>
<body>
    <div>
       
        <!--头部--有分类-->
        <div class="cate_header">
            <div class="putong_top">
                <a href="javascript:history.go(-1);"></a>
                <div><spring:message code="pattern.yinhua"></spring:message></div>
            </div>
        </div>

        <div role="main" class="main" style="background:#F0F0F2;padding-bottom:0px;">
         
            <!--工艺-->
            <div id="gongyi" class="gongyi">
                <p><spring:message code="pattern.digital"></spring:message></p>
                <ul>
                <c:forEach items="${patternPrintList }" var="patternPrint">
                    <li>
                        <input onclick="jisuan()" type="radio" rel="${patternPrint.ppId }" mani="${patternPrint.ppPrice }" name="gy" />
                        <label>${patternPrint.ppName }</label>
                        <span class="ri">${patternPrint.ppPrice }<spring:message code="pattern.unit"></spring:message></span>
                    </li>
                    </c:forEach>
                </ul>
                <div class="imputedprice">
                <p><spring:message code="pattern.priceType"></spring:message>： </p>
                <table class="imputedpricetable">
				  <tr>
				    <th scope="col">1~50m</th>
				    <th scope="col">51~300m</th>
				    <th scope="col">301~1000m</th>
				    <th scope="col">1000m+</th>
				  </tr>
				  <tr>
				    <td>200%</td>
				    <td>150%</td>
				    <td>120%</td>
				    <td>100%</td>
				  </tr>
				</table>
				<p><spring:message code="pattern.dispersed"></spring:message></p>
				<p><spring:message code="pattern.activity"></spring:message></p>
				<p><spring:message code="pattern.acidic"></spring:message></p>
                </div>
            </div>

            <!--数量、购买-->
            <div class="shu_buy">
                <div class="shu_bot">
                    <div class="shu">
                        <label class="le"><spring:message code="pattern.processing"></spring:message></label>
                        <div class=shu_spiner><input onpropertychange="jisuan()" oninput="jisuan()" id="spinnerId" type="text" class="spinner le"/></div>
                        <div class="clr"></div>
                    </div>
                    <div class="zong"><spring:message code="pattern.lump"></spring:message><div class="f-r"><span id="zongjia">0</span><spring:message code="pattern.yuan"></spring:message></div><div class="clr"></div></div>
                </div>
                <div class="shu_btn">
                    <a href="javascript:add(2);"><spring:message code="pattern.join"></spring:message></a>
                 <a href="javascript:add(1);"><spring:message code="pattern.buy"></spring:message></a>
                   
                    <div class="clr"></div>
                </div>
            </div>

        </div>
        

   </div>
     <form method="post" action="${pageContext.request.contextPath}/api/orders/viewinsertorders" id="form">
	<input type="hidden" id="pId" name="pId" value="${pattern.pId }">
	<input type="hidden" id="ppId" name="ppId">
	<input type="hidden" id="fId" name="fId">
	<input type="hidden" id="size" name="size">
	<input type="hidden" id="status" name="status" value="0">
	
	</form>
    <script src="${pageContext.request.contextPath }/phone/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/phone/js/jquery.spinner.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/lib/layer/layer_mobile/layer.js"></script>
    <script type="text/javascript">
        $('.spinner').spinner();
        
        $('#spinnerId').parent().find('button').click(function(){
    		jisuan()
    	});
        function jisuan(){
        	var yinhua=$('#gongyi').find('input:radio:checked').attr("mani");
        	
   	        $("#spinnerId").val(parseInt($("#spinnerId").val()));
   	        
   			if(parseInt($("#spinnerId").val())<1){
   				$("#spinnerId").val(1);
   			}else{
   	            if(yinhua!=null){

   	        		var spinnerM2=$('#spinnerId').val();
   		        	if(spinnerM2 <= 50){
   		        		totalPirce2=parseFloat(yinhua)*spinnerM2*2;
   		        	}else if(spinnerM2 >= 51 & spinnerM2 <= 300){
   		        		totalPirce2=parseFloat(yinhua)*((spinnerM2 - 50)*1.5 + 50*2);
   		        	}else if(spinnerM2 > 300 & spinnerM2 <= 1000){
   		        		totalPirce2=parseFloat(yinhua)*((spinnerM2 - 300)*1.2 + 250*1.5 + 50*2);
   		        	}else if(spinnerM2 > 1000){
   		        		totalPirce2=parseFloat(yinhua)*((spinnerM2 - 1000)*1 + 700*1.2 + 250*1.5 + 50*2);
   		        	}
   	        	}
   			}	
        		
        	$("#zongjia").text(totalPirce2.toFixed(2));
        }
        
        function add(statu){
			var pId=null;//huaxing
			var ppId=null;//yinhua
			var fId=null;//buliao
			var size=null;
			var yinhua = document.getElementsByName("gy");
			for (var i = 0; i < yinhua.length; i++) {
				if (yinhua[i].checked) {
					ppId=$(yinhua[i]).attr("rel");
				}
			}
			size=$('#spinnerId').val();
			if(ppId==null||ppId==""||size==null||size==""||size=="0"){
				layer.open({content: '<spring:message code="pattern.chooseDesign"></spring:message>',skin: 'msg',time: 1});
   	   	   		
				 return ;
			}
			
			$("#ppId").val(ppId);
			$("#size").val(size);
			if(statu==1){
			$.ajax({
	   			 url:'${pageContext.request.contextPath }/web/orders/chakanhuaxing',
	   			 async : false,
	   			 data: {"pId":"${pattern.pId }"},
	   			 type : "GET", 
	   			 success :function(result){
	   			 if(result == "SUCCESS"){
	   				$("#form").submit();
	   			 }else{//失败
	   				layer.open({content: '<spring:message code="pattern.beenBought"></spring:message>',skin: 'msg',time: 1});
	   	   	   		
	   			 }
	   			 }
	   			 });
			}else{
				$.ajax({
	    			 url:'${pageContext.request.contextPath }/web/shoppingcart/insertshoppingcart',
	    			 async : false,
	    			 data:$("#form").serialize() ,
	    			 type : "POST", 
	    			 success :function(result){
	    			 var status=result.msg.status;
	    			 var desc=result.msg.desc;
	    			 if(status == 0){
	    				 layer.open({content: '<spring:message code="pattern.success"></spring:message>',skin: 'msg',time: 1});
	    	   	   	   		
	    			 }else if(status == 2){//失败
	    				 layer.open({content: '<spring:message code="pattern.fail"></spring:message>',skin: 'msg',time: 1});
	    	   	   	   		
	    			    }else if(status ==1){//被买断
	    			    	layer.open({content: '<spring:message code="pattern.beenBought"></spring:message>',skin: 'msg',time: 1});
	    	   	   	   		
	    			    }else if(status ==3){//被买断
	    			    	layer.open({content: '<spring:message code="pattern.noLogin"></spring:message>',skin: 'msg',time: 1});
	    	   	   	   		
	    			    }
	    			 }
	    			 });
			}
			
		}   
    </script>


</body>
</html>
